package com.xuexiang.xuidemo.slice.status;

import ohos.agp.components.Component;

import com.xuexiang.xui_lib.component.TitleBarLayout;
import com.xuexiang.xui_lib.component.status.Status;
import com.xuexiang.xui_lib.component.status.StatusComponent;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.BaseAbilitySlice;
import com.xuexiang.xuidemo.util.ToastUtil;

/**
 *
 */
public class StatusViewLayoutSlice extends BaseAbilitySlice {

    private StatusComponent statusComponent;

    @Override
    protected int getTitleBarId() {
        return ResourceTable.Id_title_bar;
    }

    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_ability_slice_status_view;
    }

    @Override
    protected void initComponents() {
        super.initComponents();
        statusComponent = (StatusComponent) findComponentById(ResourceTable.Id_status_component);

        statusComponent.setOnErrorClickListener(component -> {
            ToastUtil.showToast(component.getContext(),"点击错误状态视图");
            statusComponent.dismiss();
        });

        statusComponent.setOnLoadingClickListener(component -> {
            ToastUtil.showToast(component.getContext(),"点击正在加载状态视图");
            statusComponent.dismiss();
        });

        statusComponent.setOnCustomClickListener(component -> {
            ToastUtil.showToast(component.getContext(),"点击自定义状态视图");
            statusComponent.dismiss();
        });

        findComponentById(ResourceTable.Id_complete_btn).setClickedListener(component -> {
            statusComponent.setStatus(Status.COMPLETE);
        });
        findComponentById(ResourceTable.Id_error_btn).setClickedListener(component -> {
            statusComponent.setStatus(Status.ERROR);
        });
        findComponentById(ResourceTable.Id_loading_btn).setClickedListener(component -> {
            statusComponent.setStatus(Status.LOADING);
        });
        findComponentById(ResourceTable.Id_none_btn).setClickedListener(component -> {
            statusComponent.setStatus(Status.NONE);
        });
        findComponentById(ResourceTable.Id_custom_btn).setClickedListener(component -> {
            statusComponent.setStatus(Status.CUSTOM);
        });
    }
}
